package com.chj.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.chj.dao.OrderDAO;
import com.chj.entity.Order;
import com.chj.entity.ResultModel;
import com.chj.service.OrderService;
import com.chj.util.DateUtil;

@Service
public class OrderServiceImpl implements OrderService{

    @Resource
    private OrderDAO orderDAO;

    @Override
    public int addOrder(Order order) {

        return orderDAO.save(order);
    }

    @Override
    public Order getOrder(Order order) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<Order> getOrderBy() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<Order> getOrderList() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int modifyOrder(Order order) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int updateOrder(Order order) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public ResultModel deleteForOrder(String orderPk) {

        if (orderDAO.deleteBuOrderId(orderPk) > 0 ) {
            return new ResultModel(1, true, "");
        } else {
            return new ResultModel(0, false, "出现系统错误");
        }
    }

    @Override
    public int payForOrder(String orderPk) {

        Order order = orderDAO.get(orderPk);
        order.setPayStatus(1);
        order.setPayDate(new Date());
        return orderDAO.modify(order);
    }

    @Override
    public List<Order> getOrderByUserId(String userId) {
       
        return orderDAO.queryOrderByUserId(userId);
    }

    @Override
    public List<Order> getOrderByUserIdByNow(String userPk, Date date) {

        String dateString = DateUtil.dateToString(date, "yyyy-MM-dd");

        return orderDAO.getOrderByUserIdByNow(userPk,dateString);
    }

    @Override
    public List<Order> getOrderByUserIdByNowOver(String userPk, Date date) {

        String dateString = DateUtil.dateToString(date, "yyyy-MM-dd");
        
        return orderDAO.getOrderByUserIdByNowOver(userPk,dateString);
    }

    @Override
    public List<Order> getOrderListBy(String userName
                                    , String orderId
                                    , String createDateFrom
                                    , String createDateTo
                                    , int page
                                    , int rows) {
        
        return orderDAO.getOrderListBy(userName
                                     , orderId
                                     , createDateFrom
                                     , createDateTo
                                     , page
                                     , rows);
    }

    @Override
    public int getOrderListSizeBy(String userName
                                , String orderId
                                , String createDateFrom
                                , String createDateTo) {

        return orderDAO.getOrderListBy(userName
                                     , orderId
                                     , createDateFrom
                                     , createDateTo);
    }

}
